package com.guilin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.guilin.system.service.SurveyResponseService;
import com.guilin.vo.SurveyResponseVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.guilin.common.core.controller.BaseController;
import com.guilin.common.core.domain.AjaxResult;
import com.guilin.domain.SurveyResponse;
import com.guilin.common.utils.poi.ExcelUtil;
import com.guilin.common.core.page.TableDataInfo;

/**
 * 问卷调查记录Controller
 * 
 * @author xiaoqi
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/admin-management/response")
public class SurveyResponseController extends BaseController
{
    @Autowired
    private SurveyResponseService surveyResponseService;

    /**
     * 查询问卷调查记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin-management:response:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurveyResponse surveyResponse)
    {
        startPage();
        List<SurveyResponseVO> list = surveyResponseService.selectSurveyResponseList(surveyResponse);
        return getDataTable(list);
    }

    /**
     * 导出问卷调查记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin-management:response:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurveyResponse surveyResponse)
    {
        List<SurveyResponseVO> list = surveyResponseService.selectSurveyResponseList(surveyResponse);
        ExcelUtil<SurveyResponseVO> util = new ExcelUtil<SurveyResponseVO>(SurveyResponseVO.class);
        util.exportExcel(response, list, "问卷调查记录数据");
    }

    /**
     * 获取问卷调查记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin-management:response:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(surveyResponseService.selectSurveyResponseById(id));
    }

    /**
     * 新增问卷调查记录
     */
    @PreAuthorize("@ss.hasPermi('admin-management:response:add')")
    @PostMapping
    public AjaxResult add(@RequestBody SurveyResponse surveyResponse)
    {
        return toAjax(surveyResponseService.insertSurveyResponse(surveyResponse));
    }

    /**
     * 修改问卷调查记录
     */
    @PreAuthorize("@ss.hasPermi('admin-management:response:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody SurveyResponse surveyResponse)
    {
        return toAjax(surveyResponseService.updateSurveyResponse(surveyResponse));
    }

    /**
     * 删除问卷调查记录
     */
    @PreAuthorize("@ss.hasPermi('admin-management:response:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surveyResponseService.deleteSurveyResponseByIds(ids));
    }
}
